package com.liuyi.liuyimodulardemo.crypto;

import com.liuyi.framework.web.encrypt.EnableLiuyiCrypto;
import com.liuyi.framework.web.encrypt.EncryptionKeyStored;
import com.liuyi.framework.web.encrypt.Rsa;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 配置文件类型的储存方式
 * 也可以选择其他类型
 * 这个是简易版的，省事
 * </p>
 */
@Service
//要加这个启动注解
@EnableLiuyiCrypto
public class YmlEncryptionKeyStored implements EncryptionKeyStored {

    @Resource
    private RsaYml rsaYml;

    @Override
    public Rsa getRsa() {
        return rsaYml.getRsa().get(rsaYml.getRsa().size() - 1);
    }

    @Override
    public Rsa getRsa(Integer version) {
        return rsaYml.getRsa().get(version);
    }

    @Override
    public void set(Rsa rsa) {
        //不能动态更新
    }

    @Override
    public Integer getVersion() {
        return rsaYml.getRsa().size() - 1;
    }

    @Override
    public Integer getLastVersion() {
        return 0;
    }
}
